﻿@{
    Layout = null;
    ViewBag.Title = "模块管理——公路工程建设项目造价全过程管理系统";
}
@using KingRoad.EPM.Common.Helper
<script type="text/javascript">
    $(function () {
        //计算分栏高度
        var contentHeight = $("#tabContent").innerHeight() - $(".panelBar", navTab.getCurrentPanel()).outerHeight();
        $("#mainContent_permission_module_index").height(contentHeight);

    });
    //树
    var zNodes_permission_module_index = [];

    var zTree_permission_module_index;
    var setting_permission_module_index;
    //全局的href
    var href__permission_module_index = "/Permission/Module";
    setting_permission_module_index = {
        checkable: false,
        async: true,
        isSimpleData: true,
        editable: true,
        edit_removeBtn: false,
        edit_renameBtn: false,
        dragCopy: true,
        dragMove: true,
        asyncUrl: "/Permission/Module/GetModuleMenus",  //获取节点数据的URL地址
        //asyncDataFilter: ajaxDataFilter,
        nameCol: "FullName",
        open: false,
        treeNodeKey: "Id",
        treeNodeParentKey: "ParentId",
        callback: {
            //             beforeAsync: zTreeBeforeAsync,
            asyncSuccess: zTreeOnAsyncSuccess_permission_module_index,
            //             asyncError: zTreeOnAsyncError,
            click: zTreeOnClick_permission_module_index,
            //拖拽之前事件处理
            beforeDrop: zTreeBeforeDrop__permission_module_index,
            //拖拽功能
            drop: zTreeOnDrop_permission_module_index
        }
    };

    function zTreeOnAsyncSuccess_permission_module_index(event, treeId, treeNode, msg) {
        //异步成功
    }
    function zTreeBeforeDrop__permission_module_index(treeId, treeNode, targetNode, moveType) {
        return confirm("确定移动 " + treeNode.FullName + " 到 " + targetNode.FullName + "？");
    }
    function zTreeOnDrop_permission_module_index(event, treeId, treeNode, targetNode, moveType) {
        $.post("/Permission/Module/Move", { "Id": treeNode.Id, "pid": targetNode.Id }, dialogMove_permission_module_index, "json");
    }
    //树的单击事件
    function zTreeOnClick_permission_module_index(event, treeId, treeNode) {
        //alert(treeNode.Id);
        $("#rightDetail_permission_module_index").load("/Permission/Module/Details/" + treeNode.Id, null, function () {
            //            if ("@ViewBag.Add" == "True") {
            //添加
            var addUrl_permission_module_index = href__permission_module_index + "/Create/" + treeNode.Id;
            $("#add_permission_module_index").attr("href", addUrl_permission_module_index);
            //            // }
            //            //if("ViewBag.Edit"=="True"){
            //            //更新
            var editUrl_permission_module_index = href__permission_module_index + "/Edit/" + treeNode.Id;
            $("#edit_permission_module_index").attr("href", editUrl_permission_module_index);
            //            //}
            //            //if("ViewBag.Del"=="True"){
            //$("#del_permission_module_index").show();
            //}
            //移动
            var moveUrl_permission_module_index = href__permission_module_index + "/MoveNode/" + treeNode.Id;
            $("#move_permission_module_index").attr("href", moveUrl_permission_module_index);
            //ajaxbg.hide();
        });
    }

    $(document).ready(function () {
        refreshTree("/Permission/Module/GetModuleMenus");
        //模块删除操作
        //$("#del_permission_module_index").hide();
        $("#del_permission_module_index").click(function () {
            if (zTree_permission_module_index.getSelectedNode()) {
                alertMsg.confirm("您确定要删除吗？", {
                    okCall: function () {
                        $.post("/Permission/Module/Delete", { "Id": zTree_permission_module_index.getSelectedNode().Id }, dialogdel_permission_module_index, "json");
                    }
                });
            } else {
                alertMsg.error("请先选择要删除的项！");
                return false;
            }
        });
    });

    function refreshTree(asyncUrl) {
        $("#getUrl").html("");
        $("#onAsyncSuccessNode").html("<br/>");
        $("#onAsyncErrorNode").html("<br/>");
        setting_permission_module_index.asyncUrl = asyncUrl;
        if ((typeof asyncUrl) == "function") {
            $("#asyncUrlCode").html("setAsyncUrl");
        } else {
            $("#asyncUrlCode").html("\"" + asyncUrl + "\"");
        }
        zTree_permission_module_index = $("#treeModule_permission_module_index").zTree(setting_permission_module_index, zNodes_permission_module_index);
    }
    function dialogAdded_Permission_Module(json) {
        //提交回调
        //1 接收参数 2 判断成功与否 3 根据返回的数据在树上新增节点
        DWZ.ajaxDone(json);
        //alert(json.callbackType);
        if (json.statusCode == DWZ.statusCode.ok) {
            //添加成功
            if (json.callbackType == "Create") {
                var newParentNode = zTree_permission_module_index.getNodeByParam("Id", json.data.ParentId)
                //var selectedNode = zTree_permission_module_index.getSelectedNode();
                zTree_permission_module_index.addNodes(newParentNode, json.data);
            } else if (json.callbackType == "Edit") {
                //更新成功
                var selectedNode = zTree_permission_module_index.getSelectedNode();
                if (selectedNode.ParentId == json.data.ParentId) {//更新当前选中的节点
                    selectedNode.FullName = json.data.FullName;
                    zTree_permission_module_index.updateNode(selectedNode, true);
                } else {//将当前节点的父节点上移除，找到改变后的父节点并将当前新节点追加到该父节点上
                    zTree_permission_module_index.removeNode(selectedNode, true);
                    var newParentNode = zTree_permission_module_index.getNodeByParam("Id", json.data.ParentId);
                    zTree_permission_module_index.addNodes(newParentNode, json.data);
                }
                var newNode = zTree_permission_module_index.getNodeByParam("Id", json.data.Id);
                zTree_permission_module_index.selectNode(newNode);
                $("#rightDetail_permission_module_index").load("/Permission/Module/Details/" + json.data.Id);
            }
            $.pdialog.closeCurrent();
        }
    }
    //模块删除回调函数
    function dialogdel_permission_module_index(json) {
        DWZ.ajaxDone(json);
        if (json.statusCode == DWZ.statusCode.ok) {
            //删除成功
            var selectedNode = zTree_permission_module_index.getSelectedNode();
            zTree_permission_module_index.removeNode(selectedNode, true);
            //当前节点删除后添加、编辑、移动的href需要初始化
            $("#move_permission_module_index").attr("href", href__permission_module_index + "/SelectTree/{sid_user}");
            $("#add_permission_module_index").attr("href", href__permission_module_index + "/Create/0");
            $("#edit_permission_module_index").attr("href", href__permission_module_index + "/Edit/{sid_user}");
        }
    }
    //拖拽的回调方法
    function dialogMove_permission_module_index(json) {
        DWZ.ajaxDone(json);
        if (json.statusCode == DWZ.statusCode.ok) {
            //alert(json.data.Id);
            $("#rightDetail_permission_module_index").load("/Permission/Module/Details/" + json.data.Id); //重新加载右侧节点详情
        }
    }
</script>
<div class="page">
    @*顶部按钮*@
    <div class="panelBar">
        <ul class="toolBar">
            <li>@Html.PermissionButton("Permission.Module.Create", "add_permission_module_index", "add", "/Permission/Module/Create/0", "new", "dialog", "添加模块", "true", "480", "400", "添加")</li>
            <li>@Html.PermissionButton("Permission.Module.Edit", "edit_permission_module_index", "edit", "/Permission/Module/Edit/{sid_user}", "new_edit", "dialog", "编辑模块", "true", "480", "400", "编辑")</li>
            <li>@Html.PermissionButton("Permission.Module.Delete", "del_permission_module_index", "delete", "javascript:void(0);", "", "", "", "", "删除")</li>
            @*<li>@Html.PermissionButton("Permission.Module.SelectTree", "move_permission_module_index", "", "/Permission/Module/SelectTree/{sid_user}","new_move","dialog","请选择...","true","280","350","移动")</li>*@
            <li class="line">line</li>
        </ul>
    </div>
    <div id="mainContent_permission_module_index">
        <div class="leftPanel">
            @*菜单树*@
            <ul id="treeModule_permission_module_index" class="ztree">
            </ul>
        </div>
        <div class="rightPanel">
            @*表单内容*@
            <div id="rightDetail_permission_module_index">
            </div>
        </div>
    </div>
</div>
